package service.impl;

import dao.impl.GoodsDaoImpl;
import pojo.Goods;
import pojo.Page;
import service.GoodsService;

import java.util.List;

public class GoodsServiceImpl implements GoodsService {
    dao.GoodsDao dao = new GoodsDaoImpl();
    @Override
    public int add(String gname, String gprice, String gnumber) {
        return dao.goodsAdd(gname,gprice,gnumber);
    }
    @Override
    public Page findPage(Integer currentPage, Integer pageSize){
//    创建page对象
        Page page = new Page<Goods>();
//        封装当前页
        page.setCurrentPage(currentPage);
//        封装每页显示条数
        page.setPageSize(pageSize);
//        封装具体数据
        List<Goods> list = dao.findByPage(currentPage, pageSize);
        page.setList(list);
//封装条数
        Number number = dao.findTotalCount();
        int count = number.intValue();
//        总条数
        page.setTotalCount(count);
        Integer totalPage  = (count%pageSize==0)?
                count/pageSize : ((count/pageSize)+1);
        page.setTotalPage(totalPage);
        return page;
    }

    @Override
    public Boolean delect(String gid) {
        return null;
    }

    @Override
    public List<Goods> show() {
        return dao.goodsShow();
    }

    @Override
    public int deleteGoods(int gid) {
        return dao.delete(gid);
    }
}
